package com.jworkbench.jflight.interceptor;


import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class DateInsertionInterceptor implements HandlerInterceptor {

    public static String getDate() {
         Date date = new Date();
         String dateSt = date.toString();
         return dateSt;
    }
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        
        System.out.println(getDate() + ": Enter preHandle, always accept request ");
        return true;    // always continue
    }

    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        System.out.println(getDate() + ": Enter postHandle");
      //  modelAndView.addObject("currentTime", new Date());
    }

    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
         System.out.println(getDate() + ": Enter afterCompletion of request, I'm Interceptor, OVER");
        // nothing
    }

}
